// pages/order/order.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderLists:null,
    index:0,
  },
  // 修改下标
  setIndex(event){
    let index = event.target.dataset.index;
    this.setData({
      index:index
    })
  },
  // 前往支付
  gopay(e){
    let payId = e.target.dataset.orderid;
    let lists = wx.getStorageSync('goodsOrderList');
    let i = lists.findIndex(item => item.orderId == payId);
    var _this = this;
    wx.showModal({
      title: '提示',
      content: '是否前往支付',
      success (res) {
        if (res.confirm) {
          lists[i].type = 2;
          console.log(lists);
          wx.setStorageSync('goodsOrderList', lists)
          _this.setData({
            orderLists: lists
          })
        } else if (res.cancel) {
          console.log('取消')
        }
      }
    })
  },
  //催发货
  urge(e){
    let payId = e.target.dataset.orderid;
    let lists = wx.getStorageSync('goodsOrderList');
    let i = lists.findIndex(item => item.orderId == payId);
    var _this = this;
    wx.showModal({
      title: '提示',
      content: '是否催促商家发货',
      success (res) {
        if (res.confirm) {
          lists[i].type = 3;
          console.log(lists);
          wx.setStorageSync('goodsOrderList', lists);
          _this.setData({
            orderLists: lists
          })
        } else if (res.cancel) {
          console.log('取消')
        }
      }
    })
  },
  //确认收货
  confirm(e){
    let payId = e.target.dataset.orderid;
    let lists = wx.getStorageSync('goodsOrderList');
    let i = lists.findIndex(item => item.orderId == payId);
    var _this = this;
    wx.showModal({
      title: '提示',
      content: '是否确认收货',
      success (res) {
        if (res.confirm) {
          lists[i].type = 4;
          console.log(lists);
          wx.setStorageSync('goodsOrderList', lists);
          _this.setData({
            orderLists: lists
          })
        } else if (res.cancel) {
          console.log('取消')
        }
      }
    })
  },
  //前往评价
  comment(e){
    let payId = e.target.dataset.orderid;
    let lists = wx.getStorageSync('goodsOrderList');
    let i = lists.findIndex(item => item.orderId == payId);
    var _this = this;
    wx.showModal({
      title: '提示',
      content: '是否前往评价',
      success (res) {
        if (res.confirm) {
          lists[i].type = 5;
          console.log(lists);
          wx.setStorageSync('goodsOrderList', lists);
          _this.setData({
            orderLists: lists
          })
        } else if (res.cancel) {
          console.log('取消')
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
      let orderLists = wx.getStorageSync('goodsOrderList');
      this.setData({
        orderLists:orderLists
      })
      console.log(orderLists);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    // 关闭所有页面，打开到应用内的某个页面
    wx.reLaunch({
      url: '/pages/my/my',
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})